package com.gmlive.common.gmshare.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;

public class ManifestUtil {

    public static final String WECHAT_APP_ID = "share_wechat_app_id";
    public static final String QQ_APP_ID = "share_qq_app_id";

    /**
     * 读取微信的AppKey
     *
     * @param context context
     * @return String
     */
    public static String getWeixinKey(Context context) {
        try {
            ApplicationInfo appInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(),
                            PackageManager.GET_META_DATA);

            if (null != appInfo) {
                Bundle bundle = appInfo.metaData;
                String key = null;
                if (null != bundle) {
                    key = String.valueOf(bundle.get(WECHAT_APP_ID));
                }
                if (!TextUtils.isEmpty(key)) {
                    return key;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * tencent AppId
     *
     * @param context context
     * @return String
     */
    public static String getTencentQQAppId(Context context) {
        try {
            ApplicationInfo appInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(),
                            PackageManager.GET_META_DATA);

            if (null != appInfo) {
                Bundle bundle = appInfo.metaData;
                String key = null;
                if (null != bundle) {
                    key = String.valueOf(bundle.get(QQ_APP_ID));
                }

                if (!TextUtils.isEmpty(key)) {
                    return key;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "101700695";
    }

}
